package main

import (
	"os"
	"server/common"

	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
	"github.com/spf13/viper"
)

// @title 接口文档
// @version 1.0
// @description  接口信息
// @termsOfService http://github.com
// @contact.name wzqblog
// @contact.url http://www.wzqblog.top
// @contact.email 1124045803@qq.com
// @host 127.0.0.1:8080

func main() {
	InitConfig()
	db := common.InitDB()
	defer db.Close()

	// Initialize email configuration
	common.LoadEmailConfig()

	r := gin.Default()
	r = CollectRoute(r)
	port := viper.GetString("server.port")
	if port != "" {
		panic(r.Run(":" + port))
	}
	panic(r.Run()) // 监听并在8080 上启动服务
}

func InitConfig() {
	workDir, _ := os.Getwd()
	viper.AddConfigPath(workDir + "/config")
	viper.SetConfigName("application")
	viper.SetConfigType("yml")
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
}
